#include <stdio.h>
#include <stdlib.h>

typedef short int bool;
#define true    1
#define false   0

#define N 4

char D[N+1] = {0};
int M = 0;
/*
(1) Arrange the digits in the way from bigger to smaller, such that it forms the biggest number that could be made from these 4 digits;
(2) Arrange the digits in the way from smaller to bigger, such that it forms the smallest number that could be made from these 4 digits (If there is 0 among these 4 digits, the number obtained may be less than four digits);
(3) Find the difference of these two numbers that is a new four digital number.
*/

void swap(char* a, char* b, int asc)
{
    char temp;
    if((*a > *b && asc == 1) ||(*a < *b && asc == 0))
    {
        temp = *b;
        *b = *a;
        *a = temp;
        return;
    }
}

void sort(int asc)
{
    int i = 0, j = 0;

    for(i = M-1; i >= 0; i--)
    {
        for(j = 0; j < i; j++)
        {
            swap(&D[j], &D[j+1], asc);
        }
    }
}

int str2int()
{
    int i = 0;
    int sum = 0;

    for(i = 0; i < M; i++)
    {
        sum = sum * 10 + (D[i]-'0');
    }
    return sum;
}

void int2str(int n)
{
    switch(M)
    {
        case 1:sprintf(D, "%1d", n);
        break;
        case 2:sprintf(D, "%2d", n);
        break;
        case 3:sprintf(D, "%3d", n);
        break;
        case 4:sprintf(D, "%4d", n);
        break;
    }

}

void showd()
{
    printf("%s\n", D);
}

void getlenofint(int n)
{
    M = 0;
    do
    {
        M++;
        n /= 10;
    }while(n != 0);
}

bool test(n)
{
    int i = 0;

    getlenofint(n);
    if(M != 4)
    {
        return true;
    }

    for(i = 1; i <= 9; i++)
    {
        if(n == 1111*i)
        {
            return true;
        }
    }
    return false;
}

void process(int n)
{
    int n1 = 0, n2 = 0;
    int times = 0;

    printf("N=%d:\n", n);
    if(test(n) == true)
    {
        printf("No!!\n");
        return;
    }

    getlenofint(n);

    do
    {
        times++;
        getlenofint(n);
        int2str(n);
        sort(0);
        n1 = str2int();
        sort(1);
        n2 = str2int();
        n = n1 - n2;
        printf("%d-%d=%d\n", n1, n2, n);
    }while(n != 0 && n != 6174);

    printf("Ok!! %d times\n", times);
}

int main()
{
    //freopen("bin\\debug\\in.txt", "r", stdin);
    //freopen("bin\\debug\\out.txt", "w", stdout);

    int n = 0;

    while(1)
    {
        scanf("%d", &n);
        if(n == -1)
        {
            break;
        }
        process(n);
    }

    return 0;
}
